package org.siam.impl.schemas {
	
	import mx.core.IFactory;
	
	import org.siam.core.ISiamManager;
	import org.siam.core.schemas.ISchema;
	import org.siam.core.schemas.ISchemaManager;

	public class SchemaManager implements ISchemaManager {
		
		private var _siamManager:ISiamManager;
		private var _schema:ISchema;
		
		public function SchemaManager(siamManager:ISiamManager, schema:ISchema) {
			_siamManager = siamManager;
			_schema = schema;
		}

		public function get propertyIds():Array {
			return _schema.propertyIds;
		}
		
		public function findMetadata(metaKey:String, propertyId:String):String {
			return _schema.findProperty(propertyId).findMetadata(metaKey); 
		}
		
		public function format(model:Object, propertyId:String):String {
			var value:Object = model ? model[propertyId] : null;
			if (value is XMLList) {
				value = (XMLList(value).toString());
			}
			var formatterId:String = _schema.findProperty(propertyId).formatterId;
			return _siamManager.formatting.format(value, formatterId);
		}
		
		public function findRenderer(propertyId:String):IFactory {
			var rendererId:String = _schema.findProperty(propertyId).rendererId;
			return _siamManager.rendering.findRenderer(rendererId);
		}
	}
}